package com.acwing.partition13;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/2/26 21:04
 */
public class AC1215小朋友排队 {

    private static final int N = 1000010, M = 100010;
    private static int[] tr = new int[N], nums = new int[M], sum = new int[M];
    private static int n = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = Integer.parseInt(reader.readLine());
        String[] ss = reader.readLine().split(" ");
        for (int i = 0; i < n; i++) nums[i] = Integer.parseInt(ss[i]) + 1;
        //查找有多少个比当前数大的数
        for (int i = 0; i < n; i++) {
            sum[i] = ask(N - 1) - ask(nums[i]);
            add(nums[i], 1);
        }
        for (int i = 0; i < N; i++) tr[i] = 0;
        //查找有多少个比当前数小的数
        for (int i = n - 1; i >= 0; i--) {
            sum[i] += ask(nums[i] - 1);
            add(nums[i], 1);
        }
        long ans = 0;
        for (int i = 0; i < n; i++) ans += (long) sum[i] * (sum[i] + 1) / 2;
        writer.write(ans + "\n");
        writer.flush();
    }

    private static int ask(int x) {
        int res = 0;
        for (int i = x; i != 0; i -= lowbit(i)) res += tr[i];
        return res;
    }

    private static void add(int x, int k) {
        for (int i = x; i < N; i += lowbit(i)) tr[i] += k;
    }

    private static int lowbit(int x) {
        return x & -x;
    }
}
